package com.ygqh.baby.controller.admin;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.ygqh.baby.ao.DataStatus;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgBrand;
import com.ygqh.baby.service.YgBrandService;

@Controller
@RequestMapping("/admin/brand")
public class BrandController  extends BaseController<Object, java.lang.Long>{
	
    @Autowired
	private YgBrandService ygBrandService;	
	
	@RequestMapping("searchBrand")
	@ResponseBody
	public Map<String,Object> searchBrand(String q,QueryInfo queryInfo,Long supplierId) {	
		
		ResultSet<YgBrand> resultSet=ygBrandService.search(queryInfo,supplierId,q);
		
		return resultSet.toDatatables(null);
	}
	@RequestMapping("searchBrandList")
	@ResponseBody
	public List<YgBrand> searchBrandList(String q,QueryInfo queryInfo,Long supplierId) {	
		
		return ygBrandService.getBrandList(supplierId,queryInfo,q);
	}
	
	@RequestMapping("saveBrand")
	@ResponseBody
	public Message saveBrand(String brand) {
		
		YgBrand ygBrand=JSON.parseObject(brand,YgBrand.class);		
		
		ygBrand.setCreateBy(getSession().getTrueName());
		ygBrand.setCreateTime(new Date());
		return ygBrandService.saveOrUpdate(ygBrand)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	}
	
	@RequestMapping("updateBrandStatus")
	@ResponseBody
	public Message updateBrandStatus(Long id) {
		YgBrand ygBrand=new YgBrand();		
		ygBrand.setId(id);
		ygBrand.setUpdateBy(getSession().getTrueName());	
		ygBrand.setUpdateTime(new Date());	
		ygBrand.setStatus(DataStatus.Delete);
		return ygBrandService.update(ygBrand)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	}
	
}
